<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:p="http://primefaces.org/ui">

	<ui:composition template="../templates/template.xhtml">
			<ui:define name="corpo">
					<h:form id="form" acceptcharset="UTF-8">
						<input type="hidden" value="&#153;" name="bugIE" />
						<p:panel header="Entrada Produto">
							<p:messages id="messages" showDetail="false" />  
	        				<h:panelGrid columns="3" columnClasses="label, value" styleClass="grid">
	        					<h:outputText value="Data:" />
	        					<p:calendar locale="pt" value="#{entradaMB.entradaProduto.data}" label="Data" />
	        					<h:outputText value="" />
	        					
	        					<h:outputText value="Fornecedor:" />
	        					<p:selectOneMenu value="#{entradaMB.idFornecedor}">  
									<f:selectItem itemLabel="Selecione" itemValue="" /> 
						            <f:selectItems value="#{entradaMB.fornecedores}" var="fornecedor" itemLabel="#{fornecedor.nome}" itemValue="#{fornecedor.id}"/>
						      	</p:selectOneMenu>
						      	<h:outputText value="" />
						      	
						      	<h:outputText value="Valor Entrada:" />
						      	<p:inputText label="Valor Entrada" value="#{entradaMB.entradaProduto.valorEntrada}" maxlength="8" size="10" onkeypress="mascara(this, valor);" />
	        					<h:outputText value="" />
						      	
	        				</h:panelGrid>
	        			</p:panel>
	        			<br />
	        			<p:panel header="Itens Entrada" id="idItens">
							<p:dataTable var="item" value="#{entradaMB.entradaProduto.itensEntrada}" emptyMessage="Nenhum resultado encontrado.">
								<p:column>
									<f:facet name="header">  
						                    Produto  
						            </f:facet>
									<h:outputText value="#{item.produto.nome}" />
								</p:column>
								<p:column>
									<f:facet name="header">  
					                    Quantidade 
						            </f:facet>
									<h:outputText value="#{item.quantidade}" />
								</p:column>
								<p:column>
									<f:facet name="header">  
					                    Valor Compra 
						            </f:facet>
									<h:outputText value="#{item.valorcompra}" />
								</p:column>
							</p:dataTable>
							<br />
							<p:commandButton value="add" onclick="dialog.show();" type="button" />
						</p:panel>	
						<br />
						<p:commandButton value="Incluir" action="#{entradaMB.confirmar}" ajax="false" />&nbsp;
						<p:commandButton value="Cancelar" action="/pages/home/index.jsf" ajax="false" immediate="true" />
						
						<p:dialog widgetVar="dialog">
							<p:panel header="Item Entrada" id="idItem">
								<p:messages id="messagesItem" showDetail="false" /> 
								<h:panelGrid columns="2" columnClasses="label, value" styleClass="grid">
		        					<h:outputText value="Produto:" />
		        					<p:selectOneMenu value="#{entradaMB.idProduto}">  
										<f:selectItem itemLabel="Selecione" itemValue="" /> 
							            <f:selectItems value="#{entradaMB.produtos}" var="produto" itemLabel="#{produto.nome}" itemValue="#{produto.id}"/>
							      	</p:selectOneMenu>
							      	
							      	<h:outputText value="Quantidade:" />
							      	<p:inputText label="Quantidade" value="#{entradaMB.itemEntrada.quantidade}" maxlength="8" size="10" onkeypress="mascara(this, valorSemMascara);" />
		        					
		        					<h:outputText value="Valor Compra:" />
		        					<p:inputText label="Valor Compra" value="#{entradaMB.itemEntrada.valorcompra}" maxlength="8" size="10" onkeypress="mascara(this, valor);" />
		        				</h:panelGrid>
		        				<br />
		        				<p:commandButton value="Adicionar Item" action="#{entradaMB.adicionar}" ajax="true" update="form:idItens, form:idItem, form:messagesItem"/>
							</p:panel>
						</p:dialog>
	        			
					</h:form>
			</ui:define>
	</ui:composition>
</html>